// 引入封装好的网络请求包
import {
  post,
  get
} from 'request.js';

// 本地服务器地址
//const serverHostUrl = "http://localhost:8085";
const serverHostUrl = "https://wangqiang.cn.utools.club";

// weChat code2Session 通过该接口与服务器交互回获取微信的openId，就是用户ID
const code2SessionUrl = serverHostUrl + '/wechat/code2Session/';
// 用户登录
const loginUrl = serverHostUrl + '/user/login/';
//学校列表
const abroadSchoolListUrl = serverHostUrl + '/abroadSchool/list/';

//申请列表
const applicationListUrl = serverHostUrl + '/studyAbroadApplication/list/';

//收藏列表
const collectionListUrl = serverHostUrl + '/userCollectAbroadSchool/collectList/';

//收藏或取消学校
const userCollectAbroadSchoolUrl = serverHostUrl + '/userCollectAbroadSchool/addOrCancel/';

//发布
const publishApplicationUrl = serverHostUrl + '/studyAbroadApplication/add/';

/**
 * 获取openId
 */
const code2SessionFunc = (jsCode, success, fail) => {
  post(code2SessionUrl, {
    'jsCode': jsCode,
  }, function (data) {
    success(data);
  }, function (res) {
    fail(res);
  })
}

/**
 * 用户登录，根据账号自动判断是商家还是用户
 */
const loginFunc = (mobile, password, success, fail) => {
  post(loginUrl, {
    "mobile": mobile,
    "password": password
  }, function (data) {
    success(data);
  }, function (res) {
    fail(res);
  })
}
/**
 * 学校列表
 */
const abroadSchoolListFunc = (params, success, fail) => {
  post(abroadSchoolListUrl, params, function (data) {
    success(data);
  }, function (res) {
    fail(res);
  })
}
/**
 *  收藏或者取消
 * @param {*} params 
 * @param {*} success 
 * @param {*} fail 
 */
const userCollectAbroadSchoolFunc = (params, success, fail) => {
  post(userCollectAbroadSchoolUrl, params, function (data) {
    success(data);
  }, function (res) {
    fail(res);
  })
}

/**
 * 收藏列表
 */
const collectionListFunc = (params, success, fail) => {
  get(collectionListUrl, params, function (data) {
    success(data);
  }, function (res) {
    fail(res);
  })
}

/**
 * 申请列表
 */
const applicationListFunc = (params, success, fail) => {
  post(applicationListUrl, params, function (data) {
    success(data);
  }, function (res) {
    fail(res);
  })
}

const publishApplicationFunc = (params, success, fail) => {
  post(publishApplicationUrl, params, function (data) {
    success(data);
  }, function (res) {
    fail(res);
  })
}





// 把函数向外部暴露，方便直接调用
export const login = loginFunc;
export const applicationList = applicationListFunc;
export const abroadSchoolList = abroadSchoolListFunc;
export const collectionList = collectionListFunc;
export const userCollectAbroadSchool = userCollectAbroadSchoolFunc;
export const publishApplication = publishApplicationFunc;